package com.thinker.loan.consumer.service.processor;

import com.thinker.loan.consumer.model.FraudRisk;
import com.thinker.loan.consumer.model.LoanApplicationRequest;
import com.thinker.loan.consumer.enumeration.LoanStatus;
import com.thinker.loan.consumer.enumeration.RiskLevel;
import com.thinker.loan.consumer.service.FraudDetectionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class AntiFraudProcessor extends AbstractLoanProcessor {
    private final FraudDetectionService fraudService;

    @Override
    public void process(LoanApplicationRequest request) {
        FraudRisk risk = fraudService.evaluateRisk(request);
        if (risk.getRiskLevel() == RiskLevel.HIGH) {
            request.setStatus(LoanStatus.REJECTED);
            request.setRejectReason("反欺诈检查未通过: " + risk.getReason());
            return;
        }

        request.setStatus(LoanStatus.ANTI_FRAUD_PASSED);
    }
}
